package com.lock.method;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @PackageName:com.lock.method
 * @ClassName:Test01
 * @Description: getHoldCount() 返回当前线程调用lock()方法的次数
 * @Author: zhangxiaoyu
 * @date 2021/1/22 16:22
 */
public class Test01 {
    
    static ReentrantLock lock =new ReentrantLock();
    
    public static void main(String[] args){

        m1();


    }
    
    
    public static void m1(){
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName()+"- hold countp:"+lock.getHoldCount());
            //ReentrantLock 可重入锁 可以再次获得锁对象
            m2();
        } finally {
            lock.unlock();
        }
    }


    public static void m2(){
        try {
            lock.lock();
            System.out.println(Thread.currentThread().getName()+"--hold countp:"+lock.getHoldCount());
        } finally {
            lock.unlock();
        }
    }
}
